{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "魔法函数，双下划线开始，双下划线结束"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Company(object):\n",
    "    def __init__(self, employee_list):\n",
    "        self.employee = employee_list\n",
    "    \n",
    "    def __getitem__(self, item):\n",
    "        return self.employee[item]\n",
    "\n",
    "    def __len__(self):\n",
    "        return len(self.employee)\n",
    "    \n",
    "    def __str__(self):\n",
    "        return \",\".join(self.employee)\n",
    "    \n",
    "    def __repr__(self):\n",
    "        return \",\".join(self.employee)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "com = Company([\"bobby1\",\"bobby2\"])\n",
    "print(hasattr(com, \"__len__\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "company = Company([\"tom\", \"bob\", \"jane\"])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tom\n",
      "bob\n",
      "jane\n"
     ]
    }
   ],
   "source": [
    "employee = company.employee\n",
    "for em in employee:\n",
    "    print(em)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tom\n",
      "bob\n",
      "jane\n"
     ]
    }
   ],
   "source": [
    "\n",
    "for em in company:\n",
    "    print(em)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "print(len(company))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tom\n",
      "bob\n"
     ]
    }
   ],
   "source": [
    "company1 = company[:2]\n",
    "for em in company1:\n",
    "    print(em)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "魔法函数一览\n",
    "\n",
    "非数学运算 __repr__   __str__\n",
    "\n",
    "数学运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tom,bob,jane"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "company"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Nums(object):\n",
    "    def __init__(self,num):\n",
    "        self.num=num\n",
    "    def __abs__(self):\n",
    "        return abs(self.num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_num = Nums(-1)\n",
    "\n",
    "abs(my_num)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对象"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i am a cat\n",
      "i am a fish\n",
      "i am a duck\n"
     ]
    }
   ],
   "source": [
    "class Cat(object):\n",
    "    def say(self):\n",
    "        print(\"i am a cat\")\n",
    "\n",
    "class Dog(object):\n",
    "    def say(self):\n",
    "        print(\"i am a fish\")\n",
    "class Duck(object):\n",
    "    def say(self):\n",
    "        print(\"i am a duck\")\n",
    "\n",
    "animal_list = [Cat, Dog, Duck]\n",
    "for animal in animal_list:\n",
    "    animal().say()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#希望判定某个对象的类型\n",
    "from collections.abc import Sized\n",
    "isinstance(company,Sized)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "import abc\n",
    "class CacheBase(metaclass = abc.ABCMeta):\n",
    "    @abc.abstractmethod\n",
    "    def get(self,key):\n",
    "        pass\n",
    "\n",
    "    @abc.abstractclassmethod\n",
    "    def set(self,key,value):\n",
    "        raise NotImplementedError\n",
    "\n",
    "class RedisCache(CacheBase):\n",
    "    def get(self, key):\n",
    "        pass\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(<class '__main__.A'>, <class '__main__.B'>, <class '__main__.D'>, <class '__main__.C'>, <class '__main__.E'>, <class 'object'>)\n"
     ]
    }
   ],
   "source": [
    "class D:\n",
    "    pass\n",
    "\n",
    "class E:\n",
    "    pass\n",
    "\n",
    "class C(E):\n",
    "    pass\n",
    "\n",
    "class B(D):\n",
    "    pass\n",
    "\n",
    "class A(B, C):\n",
    "    pass\n",
    "\n",
    "print(A.__mro__)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "isinstance 于 type 区别"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "类变量事例变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2 3 100\n",
      "11\n"
     ]
    }
   ],
   "source": [
    "class A:\n",
    "    aa = 1\n",
    "    def __init__(self,x,y):\n",
    "        self.x = x\n",
    "        self.y = y\n",
    "\n",
    "a = A(2,3)\n",
    "A.aa = 11 #赋值到类上 所有实例共享\n",
    "a.aa = 100 #赋值到实例上\n",
    "print(a.x,a.y,a.aa)\n",
    "print(A.aa)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "类属性和实例属性以及查找顺序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "obj\n"
     ]
    }
   ],
   "source": [
    "class A:\n",
    "    name = 'A'\n",
    "    def __init__(self):\n",
    "        self.name = \"obj\"\n",
    "\n",
    "a=A()\n",
    "print(a.name)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "静态方法，类方法，实例方法,静态方法用不到类是可以使用，用到类时使用类方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Date:\n",
    "    #构造函数\n",
    "    def __init__(self, year, month, day):\n",
    "        self.year = year\n",
    "        self.month = month\n",
    "        self.day = day\n",
    "    \n",
    "    def tomorrow(self):\n",
    "        self.day += 1\n",
    "\n",
    "    @staticmethod\n",
    "    def parse_from_string(date_str):\n",
    "        year,month,day = tuple(date_str.split(\"-\"))\n",
    "        return  Date(year=year,month=month,day=day)\n",
    "    @classmethod\n",
    "    def from_string(cls,date_str):\n",
    "        year,month,day = tuple(date_str.split(\"-\"))\n",
    "        return cls(year=year,month=month,day=day)\n",
    "\n",
    "    @staticmethod\n",
    "    def valid_str(date_str):\n",
    "        year, month, day = tuple(date_str.split(\"-\"))\n",
    "        return int(year)>0 and (int(month) >0 and int(month)<=12) and (int(day) >0 and int(day)<=31)\n",
    "\n",
    "    def __str__(self):\n",
    "        return \"{year}/{month}/{day}\".format(year=self.year, month=self.month, day=self.day)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2021/11/13\n"
     ]
    }
   ],
   "source": [
    "new_day = Date(2021,11,13)\n",
    "new_day.tomorrow()\n",
    "print(new_day)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2021 11 13\n",
      "2021/11/13\n"
     ]
    }
   ],
   "source": [
    "date_str = \"2021-11-13\"\n",
    "year,month,day = tuple(date_str.split(\"-\"))\n",
    "\n",
    "print(year,month,day)\n",
    "\n",
    "new_day = Date(year=year,month=month,day=day)\n",
    "print(new_day)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2021/11/13\n",
      "2021/11/13\n"
     ]
    }
   ],
   "source": [
    "new_day = Date.parse_from_string(date_str)\n",
    "print(new_day)\n",
    "new_day = Date.from_string(date_str)\n",
    "print(new_day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "数据封装和私有属性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'shcool_name': '郭同学'}\n",
      "{'__module__': '__main__', 'name': 'user', '__dict__': <attribute '__dict__' of 'Person' objects>, '__weakref__': <attribute '__weakref__' of 'Person' objects>, '__doc__': None}\n",
      "user\n",
      "['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'name', 'shcool_name']\n"
     ]
    }
   ],
   "source": [
    "class Person:\n",
    "    name=\"user\"\n",
    "class  Student(Person):\n",
    "    def __init__(self,shcool_name):\n",
    "        self.shcool_name = shcool_name\n",
    "\n",
    "\n",
    "user = Student(\"郭同学\")\n",
    "print(user.__dict__)\n",
    "print(Person.__dict__)\n",
    "print(user.name)\n",
    "\n",
    "print(dir(user))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(<class '__main__.D'>, <class '__main__.B'>, <class '__main__.C'>, <class '__main__.A'>, <class 'object'>)\n",
      "D\n",
      "B\n",
      "C\n",
      "A\n"
     ]
    }
   ],
   "source": [
    "class A:\n",
    "    def __init__(self):\n",
    "        print (\"A\")\n",
    "\n",
    "class B(A):\n",
    "    def __init__(self):\n",
    "        print (\"B\")\n",
    "        super().__init__()\n",
    "\n",
    "class C(A):\n",
    "    def __init__(self):\n",
    "        print (\"C\")\n",
    "        super().__init__()\n",
    "        \n",
    "class D(B, C):\n",
    "    def __init__(self):\n",
    "        print (\"D\")\n",
    "        super(D, self).__init__()\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    print(D.__mro__)\n",
    "    d = D()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "code started\n",
      "key error\n",
      "finally\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "def exe_try():\n",
    "    try:\n",
    "        print (\"code started\")\n",
    "        raise KeyError\n",
    "        return 1\n",
    "    except KeyError as e:\n",
    "        print (\"key error\")\n",
    "        return 2\n",
    "    else:\n",
    "        print (\"other error\")\n",
    "        return 3\n",
    "    finally:\n",
    "        print (\"finally\")\n",
    "\n",
    "result = exe_try()\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#上下文管理器协议"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Sample:\n",
    "    def __enter__(self):\n",
    "        print (\"enter\")\n",
    "        #获取资源\n",
    "        return self\n",
    "    def __exit__(self, exc_type, exc_val, exc_tb):\n",
    "        #释放资源\n",
    "        print (\"exit\")\n",
    "    def do_something(self):\n",
    "        print (\"doing something\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "enter\n",
      "doing something\n",
      "exit\n"
     ]
    }
   ],
   "source": [
    "with Sample() as sample:\n",
    "    sample.do_something()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "contextlib 简化上下文管理器"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "file open\n",
      "file processing\n",
      "file end\n"
     ]
    }
   ],
   "source": [
    "import contextlib\n",
    "@contextlib.contextmanager\n",
    "def file_open(file_name):\n",
    "    print (\"file open\")\n",
    "    yield {} #生成器\n",
    "    print (\"file end\")\n",
    "\n",
    "with file_open(\"bobby.txt\") as f_opened:\n",
    "    print (\"file processing\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4]\n"
     ]
    }
   ],
   "source": [
    "a = [1,2]\n",
    "c = a+[3,4]\n",
    "print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4]\n"
     ]
    }
   ],
   "source": [
    "a+=[3,4]\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6]\n"
     ]
    }
   ],
   "source": [
    "a+=(5,6)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+= 调用的魔法函数__iadd__,iadd__调用extend"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#模式[start:end:step]\n",
    "\"\"\"\n",
    "    其中，第一个数字start表示切片开始位置，默认为0；\n",
    "    第二个数字end表示切片截止（但不包含）位置（默认为列表长度）；\n",
    "    第三个数字step表示切片的步长（默认为1）。\n",
    "    当start为0时可以省略，当end为列表长度时可以省略，\n",
    "    当step为1时可以省略，并且省略步长时可以同时省略最后一个冒号。\n",
    "    另外，当step为负整数时，表示反向切片，这时start应该比end的值要大才行。\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3, 4, 5, 6, 7, 9, 11, 13, 15, 17]\n",
      "[17, 15, 13, 11, 9, 7, 6, 5, 4, 3]\n",
      "[3, 5, 7, 11, 15]\n",
      "[4, 6, 9, 13, 17]\n",
      "[6, 7, 9]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aList = [3, 4, 5, 6, 7, 9, 11, 13, 15, 17]\n",
    "\n",
    "print (aList[::])  # 返回包含原列表中所有元素的新列表\n",
    "print (aList[::-1])  # 返回包含原列表中所有元素的逆序列表\n",
    "print (aList[::2])  # 隔一个取一个，获取偶数位置的元素\n",
    "print (aList[1::2])  # 隔一个取一个，获取奇数位置的元素\n",
    "print (aList[3:6])  # 指定切片的开始和结束位置\n",
    "aList[0:100]  # 切片结束位置大于列表长度时，从列表尾部截断\n",
    "aList[100:]  # 切片开始位置大于列表长度时，返回空列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "aList[len(aList):] = [9]  # 在列表尾部增加元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3, 4, 5, 6, 7, 9, 11, 13, 15, 17, 9]\n"
     ]
    }
   ],
   "source": [
    "print(aList)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 15, 17, 9]\n"
     ]
    }
   ],
   "source": [
    "aList[0:0]=[1,2]\n",
    "print(aList)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 4, 5, 6, 7, 9, 11, 13, 15, 17, 9]\n"
     ]
    }
   ],
   "source": [
    "aList[3:3]=[4]\n",
    "print(aList)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 1, 4, 4, 5, 6, 7, 9, 11, 13, 15, 17, 9]\n"
     ]
    }
   ],
   "source": [
    "aList[:3]=[2,1]\n",
    "print(aList)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 1, 4, 4, 5, 6]\n"
     ]
    }
   ],
   "source": [
    "aList[3:] = [4, 5, 6]  # 等号两边的列表长度也可以不相等\n",
    "print(aList)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 0, 4, 0, 6]\n"
     ]
    }
   ],
   "source": [
    "aList[::2] = [0] * 3  # 隔一个修改一个\n",
    "print (aList)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['a', 1, 'b', 4, 'c', 6]\n"
     ]
    }
   ],
   "source": [
    "aList[::2] = ['a', 'b', 'c']  # 隔一个修改一个\n",
    "print (aList)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "attempt to assign sequence of size 2 to extended slice of size 3",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-14-416ee0acc632>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0maList\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m  \u001b[1;31m# 左侧切片不连续，等号两边列表长度必须相等\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0mprint\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0maList\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mValueError\u001b[0m: attempt to assign sequence of size 2 to extended slice of size 3"
     ]
    }
   ],
   "source": [
    "aList[::2] = [1,2]  # 左侧切片不连续，等号两边列表长度必须相等\n",
    "print (aList)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[4, 'c', 6]\n"
     ]
    }
   ],
   "source": [
    "del aList[:3]  # 切片元素连续\n",
    "print (aList)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['c']\n"
     ]
    }
   ],
   "source": [
    "del aList[::2]  # 切片元素不连续，隔一个删一个\n",
    "print (aList)"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "73e03da126b73bfff3642ec5261d56fa25c444ea595de51041687efaa60dda41"
  },
  "kernelspec": {
   "display_name": "Python 3.8.8 64-bit ('base': conda)",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
